#ifndef RECENTCHANGE_H
#define RECENTCHANGE_H

#include "stdafx.h"
#include <QListWidgetItem>
#include <QListWidget>

class CRecentChange : public QObject, public QListWidgetItem
{
	Q_OBJECT;

private:
	QString m_pageName;
	QString m_editor;
	int m_change;
	unsigned int m_diff;
	float m_probability;
	QString m_remark;
	QString m_bot;
	unsigned int m_rand;

public:
	CRecentChange(QListWidget *parent);
	~CRecentChange();

	void SetPageName(QString pageName) { m_pageName = pageName; UpdateText(); };
	void SetEditor(QString editor) { m_editor = editor; UpdateText(); };
	void SetChange(int change) { m_change = change; UpdateText(); };
	void SetProbability(float probability) { m_probability = probability; UpdateText(); };
	void SetDiff(unsigned int diff) { m_diff = diff; UpdateText(); };
	void SetRemark(QString remark) { m_remark = remark; UpdateText(); };
	void SetBot(QString bot) { m_bot = bot; UpdateText(); };

	unsigned int GetDiff() const { return m_diff; };
	unsigned int GetRandomID() const {return m_rand; };
	QString GetRemark() const { return m_remark; };
	QString GetBot() const { return m_bot; };
	float GetProbability() const { return m_probability; };
	QString GetPageName() const { return m_pageName; };
	QString GetEditor() const { return m_editor; };
	int GetChange() const { return m_change; };

private:
	void UpdateText() { 
		QString msg;
		QTextStream stream(&msg);
		stream << m_pageName << " (" << m_change << ")";
		setText(msg);

		QColor color;
		color.setRedF(m_probability > 0.5f ? ((m_probability - 0.5f) * 2.0f) : 0.0f);
		color.setGreenF(m_probability < 0.5f ? ((0.5f - m_probability) * 2.0f) : 0.0f);
		color.setBlueF(0.0f);
		setTextColor(color);
	}
};

#endif // RECENTCHANGE_H
